package adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.SeekBar;

import com.example.lxh.testinfo.R;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.BarChart;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

import java.util.ArrayList;
import java.util.List;

import format.myAxisformat;

/**
 * Created by Lxh on 2018/1/9.
 */

public class ViewPagerChart extends PagerAdapter implements SeekBar.OnSeekBarChangeListener, OnChartValueSelectedListener {
    private Context context;
    private List<View> viewList;
    private LinearLayout m_layout_Chart;
    private PieChart mpieChart_1;
    private PieChart mpieChart_2;
    private HorizontalBarChart mhBarChart;
    private String[] mMonths =
            new String[]{"5条以上违章", "3-5条违章", "1-2条违章"};
    private View view;
    private GraphicalView graphicalView;
    private com.github.mikephil.charting.charts.BarChart mBarChart;
    private HorizontalBarChart mBarChart_1;
    private String[] xAxisMath = new String[]{
            "机动车逆行行驶", "违规使用专用车道", "违反禁令标志指示",
            "不按规定系安全带", "机动车不走机动车道", "违反信号灯规定",
            "违反禁止标线指示", "违规停车拒绝驶离", "违规驶入导向车道",
            "超速行驶", ""
    };

    public ViewPagerChart(Context context, List<View> viewList) {
        this.context = context;
        this.viewList = viewList;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(viewList.get(position));
        view = viewList.get(position);
        m_layout_Chart = view.findViewById(R.id.picChart);
        switch (position) {
            case 0:
                setView_1();
                break;
            case 1:
                setView_2();
                break;
            case 2:
                setView_3();
                break;
            case 3:
                setView_4();
                break;
            case 4:
                setView_5();
                break;
            case 5:
                setView_6();
                break;
            case 6:
                setView_7();
                break;
        }
        return viewList.get(position);
    }

    private void setView_7() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.horzrt_1_layout, null);
        mBarChart_1 = view.findViewById(R.id.chart2);
        mBarChart_1.setOnChartValueSelectedListener(this);
        mBarChart_1.setDrawBarShadow(false);
        mBarChart_1.getDescription().setEnabled(false);
        mBarChart_1.setDrawValueAboveBar(true);
        mBarChart_1.setMaxVisibleValueCount(60);
        mBarChart_1.setPinchZoom(true);
        mBarChart_1.setDrawGridBackground(false);

        final XAxis xAxis = mBarChart_1.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawAxisLine(true);
        xAxis.setDrawGridLines(false);
        xAxis.setGranularity(10f);
        xAxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return xAxisMath[(int) value / xAxisMath.length];
            }
        });

        YAxis yAxis = mBarChart_1.getAxisLeft();
        yAxis.setDrawAxisLine(true);
        yAxis.setDrawGridLines(false);
        yAxis.setAxisMinimum(0f);
        yAxis.setValueFormatter(new myAxisformat());

        YAxis yAxis_1 = mBarChart_1.getAxisRight();
        yAxis_1.setDrawAxisLine(true);
        yAxis_1.setDrawGridLines(false);
        yAxis_1.setAxisMinimum(0f);
        yAxis_1.setValueFormatter(new myAxisformat());

        setBarChart_Data(12, 50);
        mBarChart_1.setFitBars(true);
        mBarChart_1.animateY(2500);
        Legend legend = mBarChart_1.getLegend();
        legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        legend.setDrawInside(false);
        legend.setFormSize(8f);
        legend.setEnabled(false);
        legend.setXEntrySpace(4f);
        m_layout_Chart.addView(view);
    }

    private void setView_6() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.histgramelayout, null);
        mBarChart = view.findViewById(R.id.chart_barchart);
        mBarChart.getDescription().setEnabled(false);
        mBarChart.setDrawValueAboveBar(true);
        mBarChart.setOnChartValueSelectedListener(this);
        mBarChart.setMaxVisibleValueCount(60);
        mBarChart.setPinchZoom(false);
        mBarChart.setDrawBarShadow(false);

        XAxis xAxis = mBarChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(true);
        xAxis.setGranularity(10f);
        xAxis.setTextSize(20);
        xAxis.setValueFormatter(new myAxisformat());

        YAxis yAxis = mBarChart.getAxisLeft();
        yAxis.setDrawAxisLine(true);
        yAxis.setDrawGridLines(false);
        yAxis.setAxisMinimum(0f);
        yAxis.setValueFormatter(new myAxisformat());

        setBarChart_Data_1(12, 50);
        mBarChart.setFitBars(true);
        mBarChart.getAxisLeft().setDrawGridLines(false);
        mBarChart.animateY(2500);

        Legend legend = mBarChart.getLegend();
        legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        legend.setDrawInside(false);
        legend.setFormSize(8f);
        legend.setXEntrySpace(4f);
        mBarChart.getLegend().setEnabled(false);
        m_layout_Chart.addView(view);
    }


    private void setBarChart_Data(int count, int range) {
        float barWidth = 9f;
        float spaceForBar = 10f;
        ArrayList<BarEntry> yVales = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * range);
            yVales.add(new BarEntry(i * spaceForBar, val));
        }
        BarDataSet set;
        if (mBarChart_1.getData() != null && mBarChart_1.getData().getDataSetCount() > 0) {
            set = (BarDataSet) mBarChart_1.getData().getDataSetByIndex(0);
            set.setValues(yVales);
            mBarChart_1.getData().notifyDataChanged();
            mBarChart_1.notifyDataSetChanged();
        } else {
            set = new BarDataSet(yVales, "data");
            set.setDrawIcons(false);
            ArrayList<IBarDataSet> dataSets = new ArrayList<>();
            dataSets.add(set);
            BarData data = new BarData(dataSets);
            data.setValueTextSize(10f);
            data.setBarWidth(barWidth);
            mBarChart_1.setData(data);
        }
        List<Integer> list = new ArrayList<>();
        list.add(Color.parseColor("#48687e"));
        list.add(Color.parseColor("#2a0f18"));
        list.add(Color.parseColor("#070760"));
        list.add(Color.parseColor("#4f622a"));
        list.add(Color.parseColor("#b8b0da"));
        list.add(Color.parseColor("#769339"));
        list.add(Color.parseColor("#983439"));
        list.add(Color.parseColor("#Fdc701"));
        list.add(Color.parseColor("#4f7fba"));
        list.add(Color.parseColor("#e86a0f"));
        list.add(Color.parseColor("#973377"));
        list.add(Color.parseColor("#381716"));

        set.setColors(list);
        mBarChart_1.invalidate();
    }

    private void setBarChart_Data_1(int count, int range) {
        float barWidth = 9f;
        float spaceForBar = 10f;
        ArrayList<BarEntry> yVales = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * range);
            yVales.add(new BarEntry(i * spaceForBar, val));
        }
        BarDataSet set;
        if (mBarChart.getData() != null && mBarChart.getData().getDataSetCount() > 0) {
            set = (BarDataSet) mBarChart.getData().getDataSetByIndex(0);
            set.setValues(yVales);
            mBarChart.getData().notifyDataChanged();
            mBarChart.notifyDataSetChanged();
        } else {
            set = new BarDataSet(yVales, "data");
            set.setDrawIcons(false);
            ArrayList<IBarDataSet> dataSets = new ArrayList<>();
            dataSets.add(set);
            BarData data = new BarData(dataSets);
            data.setValueTextSize(10f);
            data.setBarWidth(barWidth);
            mBarChart.setData(data);
        }
        List<Integer> list = new ArrayList<>();
        list.add(Color.parseColor("#48687e"));
        list.add(Color.parseColor("#2a0f18"));
        list.add(Color.parseColor("#070760"));
        list.add(Color.parseColor("#4f622a"));
        list.add(Color.parseColor("#b8b0da"));
        list.add(Color.parseColor("#769339"));
        list.add(Color.parseColor("#983439"));
        list.add(Color.parseColor("#Fdc701"));
        list.add(Color.parseColor("#4f7fba"));
        list.add(Color.parseColor("#e86a0f"));
        list.add(Color.parseColor("#973377"));
        list.add(Color.parseColor("#381716"));
        set.setColors(list);
        mBarChart.invalidate();
    }


    private void setView_5() {
        String[] title = new String[]{"无违规", "有违规"};
        List<double[]> vs = new ArrayList<>();
        vs.add(new double[]{16300d, 18300d});
        vs.add(new double[]{15431d, 12333d});
        XYMultipleSeriesDataset dataset = setBarData(title, vs);
        int[] colors = new int[]{Color.parseColor("#EB7208"),
                Color.parseColor("#6A9800")
        };
        XYMultipleSeriesRenderer renderer = serRenderer(colors);
        renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
        renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
        graphicalView = ChartFactory.getBarChartView(view.getContext(),
                dataset, renderer, BarChart.Type.STACKED
        );
        m_layout_Chart.addView(graphicalView);
    }

    private XYMultipleSeriesRenderer serRenderer(int[] colors) {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

        renderer.setAxisTitleTextSize(16);
        renderer.setChartTitleTextSize(30);
        renderer.setLabelsTextSize(15);
        renderer.setLegendTextSize(15);
        renderer.setChartTitle("男性和女性有无车辆违章占卜统计表");
        renderer.setYLabels(9);
        renderer.setShowGridX(true);
        renderer.setMargins(new int[]{50, 80, 15, 10});
        renderer.setXLabels(0);
        renderer.addXTextLabel(1, "女性");
        renderer.addYTextLabel(2, "男性");
        renderer.setXAxisMin(0.5);
        renderer.setXAxisMax(5.5);
        renderer.setYAxisMax(20000);
        renderer.setYAxisMin(13000);

        renderer.setDisplayValues(true);
        renderer.setAxesColor(Color.BLACK);
        renderer.setLabelsColor(Color.BLACK);
        renderer.setMarginsColor(Color.WHITE);
        renderer.setXLabelsAlign(Paint.Align.RIGHT);
        renderer.setYLabelsAlign(Paint.Align.RIGHT);

        renderer.setPanEnabled(false);
        renderer.setZoomRate(1.0f);
        renderer.setBarSpacing(0.2f);
        for (int color : colors) {
            SimpleSeriesRenderer r = new SimpleSeriesRenderer();
            r.setColor(color);
            renderer.addSeriesRenderer(r);
        }
        return renderer;
    }

    private XYMultipleSeriesDataset setBarData(String[] title, List<double[]> vs) {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        for (int i = 0; i < title.length; i++) {
            CategorySeries series = new CategorySeries(title[i]);
            double[] d = vs.get(i);
            int seriesLenght = d.length;
            for (int k = 0; k < seriesLenght; k++) {
                series.add(d[k]);
            }
            dataset.addSeries(series.toXYSeries());
        }
        return dataset;
    }

    private void setView_4() {
        String[] titles = new String[]{"无违规", "有违规"};
        List<double[]> vs = new ArrayList<>();
        vs.add(new double[]{315, 131, 113, 444, 677, 434});
        vs.add(new double[]{121, 111, 106, 123, 111, 142});
        XYMultipleSeriesDataset dataset = dataSet(titles, vs);
        int[] colors = new int[]{Color.parseColor("#EB7208"),
                Color.parseColor("#6A9800")};
        XYMultipleSeriesRenderer renderer = setrender(colors);

        renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
        renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
        graphicalView = ChartFactory.getBarChartView(view.getContext(), dataset, renderer, BarChart.Type.STACKED);
        m_layout_Chart.addView(graphicalView);
    }

    private XYMultipleSeriesDataset dataSet(String[] titles, List<double[]> vs) {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        int lenght = titles.length;
        for (int i = 0; i < lenght; i++) {
            CategorySeries series = new CategorySeries(titles[i]);
            double[] d = vs.get(i);
            int serieslenght = d.length;
            for (int k = 0; k < serieslenght; k++) {
                series.add(d[k]);
            }
            dataset.addSeries(series.toXYSeries());
        }
        return dataset;
    }

    public XYMultipleSeriesRenderer setrender(int[] render) {
        XYMultipleSeriesRenderer Srenderer = new XYMultipleSeriesRenderer();
        Srenderer.setAxisTitleTextSize(16f);
        Srenderer.setLabelsTextSize(15);
        Srenderer.setChartTitleTextSize(30);
        Srenderer.setLegendTextSize(15);
        Srenderer.setChartTitle("年龄群体车辆违章的占比统计表");
        Srenderer.setXLabels(0);
        Srenderer.setYLabels(6);
        Srenderer.setShowGridX(true);
        Srenderer.setGridColor(Color.BLACK);
        Srenderer.setMargins(new int[]{50, 80, 15, 10});
        Srenderer.addXTextLabel(1, "90后");
        Srenderer.addXTextLabel(2, "80后");
        Srenderer.addXTextLabel(3, "70后");
        Srenderer.addXTextLabel(4, "60后");
        Srenderer.addXTextLabel(5, "50后");
        Srenderer.setXAxisMax(7.5d);
        Srenderer.setXAxisMin(0.5d);
        Srenderer.setYAxisMax(1200);
        Srenderer.setYAxisMin(1);
        Srenderer.setAxesColor(Color.WHITE);
        Srenderer.setMarginsColor(Color.WHITE);

        Srenderer.setXLabelsAlign(Paint.Align.RIGHT);
        Srenderer.setYLabelsAlign(Paint.Align.RIGHT);
        Srenderer.setPanEnabled(false);
        Srenderer.setZoomRate(1.5f);
        Srenderer.setBarSpacing(0.5f);
        Srenderer.setLabelsColor(Color.BLACK);
        for (int color : render) {
            SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
            renderer.setColor(color);
            Srenderer.addSeriesRenderer(renderer);
        }
        return Srenderer;
    }

    private void setView_3() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View Viewinflater = inflater.inflate(R.layout.horzrtlayout, null);
        mhBarChart = Viewinflater.findViewById(R.id.chart1);
        mhBarChart.setOnChartValueSelectedListener(this);
        mhBarChart.setDrawBarShadow(false);
        mhBarChart.setDrawValueAboveBar(true);
        mhBarChart.getDescription().setEnabled(false);
        mhBarChart.setMaxVisibleValueCount(60);
        mhBarChart.setPinchZoom(true);
        mhBarChart.setDrawGridBackground(false);
        mhBarChart.setDoubleTapToZoomEnabled(false);

        XAxis x = mhBarChart.getXAxis();
        x.setPosition(XAxis.XAxisPosition.BOTTOM);
        x.setDrawGridLines(false);
        x.setDrawAxisLine(true);
        x.setGranularity(10f);
        x.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return mMonths[(int) value % mMonths.length];
            }
        });

        YAxis y = mhBarChart.getAxisLeft();
        y.setDrawGridLines(false);
        y.setDrawAxisLine(true);
        y.setValueFormatter(new myAxisformat());

        YAxis yLeft = mhBarChart.getAxisRight();
        yLeft.setDrawGridLines(false);
        yLeft.setDrawAxisLine(true);
        yLeft.setAxisMinimum(0f);
        yLeft.setValueFormatter(new myAxisformat());

        setData(3, 50);
        mhBarChart.setFitBars(true);
        mhBarChart.animateY(2500);
        Legend legend = mhBarChart.getLegend();
        legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        legend.setDrawInside(false);
        legend.setFormSize(8f);
        legend.setEnabled(false);
        legend.setXEntrySpace(4f);
        m_layout_Chart.addView(Viewinflater);
    }

    private void setData(int count, int range) {
        float barWidth = 9f;
        float spaceForBar = 10f;
        ArrayList<BarEntry> yVals = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * range);
            yVals.add(new BarEntry(i * spaceForBar, val));
        }
        BarDataSet set;
        if (mhBarChart.getData() != null && mhBarChart.getData().getDataSetCount() > 0) {
            set = (BarDataSet) mhBarChart.getData().getDataSetByIndex(0);
            set.setValues(yVals);
            mhBarChart.getData().notifyDataChanged();
            mhBarChart.notifyDataSetChanged();
        } else {
            set = new BarDataSet(yVals, "data");
            set.setDrawIcons(false);
            ArrayList<IBarDataSet> dataSets = new ArrayList<>();
            dataSets.add(set);
            BarData data = new BarData(dataSets);
            data.setValueTextSize(10f);
            data.setBarWidth(barWidth);
            mhBarChart.setData(data);
        }
        List<Integer> listColor = new ArrayList<>();
        listColor.add(Color.RED);
        listColor.add(Color.BLUE);
        listColor.add(Color.GREEN);
        set.setColors(listColor);
    }

    private void setView_2() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View piChart_View = inflater.inflate(R.layout.pic_dome_layout, null);
        mpieChart_2 = piChart_View.findViewById(R.id.mPieChart);
        mpieChart_2.setUsePercentValues(true);
        mpieChart_2.getDescription().setEnabled(false);
        mpieChart_2.setExtraOffsets(5, 10, 5, 5);
        mpieChart_2.setDrawHoleEnabled(false);
        mpieChart_2.setHoleColor(Color.WHITE);

        mpieChart_2.setTransparentCircleAlpha(110);
        mpieChart_2.setTransparentCircleColor(Color.WHITE);
        mpieChart_2.setHoleRadius(58f);
        mpieChart_2.setTransparentCircleRadius(61f);
        mpieChart_2.setDrawCenterText(true);
        mpieChart_2.setRotationEnabled(true);
        mpieChart_2.setHighlightPerTapEnabled(true);

        ArrayList<PieEntry> entries = new ArrayList<>();
        entries.add(new PieEntry(34.1f, "无重复违规"));
        entries.add(new PieEntry(76.1f, "有重复违规"));
        setPieChartData_1(entries);
        mpieChart_2.animateY(1400,
                Easing.EasingOption.EaseInOutQuad);
        Legend legend = mpieChart_2.getLegend();
        legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        legend.setOrientation(Legend.LegendOrientation.VERTICAL);
        legend.setDrawInside(false);
        legend.setXEntrySpace(7f);
        legend.setYEntrySpace(0f);
        mpieChart_2.setEntryLabelColor(Color.WHITE);
        mpieChart_2.setEntryLabelTextSize(15f);
        m_layout_Chart.addView(piChart_View);
    }

    private void setView_1() {
        LayoutInflater inflater_1 = LayoutInflater.from(context);
        View pieChart_View = inflater_1.inflate(R.layout.pic_dome_layout, null);
        mpieChart_1 = pieChart_View.findViewById(R.id.mPieChart);

        mpieChart_1.setUsePercentValues(true);
        mpieChart_1.getDescription().setEnabled(false);
        mpieChart_1.setExtraOffsets(5, 10, 5, 5);//左 上  右  下
        mpieChart_1.setDrawHoleEnabled(false);
        mpieChart_1.setHoleColor(Color.WHITE);

        mpieChart_1.setTransparentCircleAlpha(110);
        mpieChart_1.setTransparentCircleColor(Color.WHITE);
        mpieChart_1.setTransparentCircleRadius(61f);
        mpieChart_1.setHoleRadius(58f);

        mpieChart_1.setDrawCenterText(true);
        mpieChart_1.setRotationEnabled(true);
        mpieChart_1.setHighlightPerTapEnabled(true);

        ArrayList<PieEntry> entries_1 = new ArrayList<>();
        entries_1.add(new PieEntry(23.1f, "无违规"));
        entries_1.add(new PieEntry(75.5f, "有违规"));
        setPieChartData(entries_1);
        mpieChart_1.animateY(1400,
                Easing.EasingOption.EaseInOutQuad);
        Legend legend_1 = mpieChart_1.getLegend();
        legend_1.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        legend_1.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        legend_1.setOrientation(Legend.LegendOrientation.VERTICAL);
        legend_1.setDrawInside(false);
        legend_1.setXEntrySpace(7f);
        legend_1.setYEntrySpace(0f);
        legend_1.setYOffset(0f);
        mpieChart_1.setEntryLabelColor(Color.WHITE);
        mpieChart_1.setEntryLabelTextSize(15f);
        m_layout_Chart.addView(pieChart_View);
    }


    public void setPieChartData_1(ArrayList<PieEntry> pieChartData_1) {
        PieDataSet dataSet = new PieDataSet(pieChartData_1, "");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);
        ArrayList<Integer> list = new ArrayList<>();
        list.add(Color.parseColor("#4572A7"));
        list.add(Color.parseColor("#AA4643"));
        dataSet.setColors(list);
        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(15f);
        data.setValueTextColor(Color.WHITE);
        mpieChart_2.setData(data);
        mpieChart_2.highlightValue(null);
        mpieChart_2.invalidate();

    }

    public void setPieChartData(ArrayList<PieEntry> pieChartData) {
        PieDataSet dataSet = new PieDataSet(pieChartData, "");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);
        ArrayList<Integer> colors = new ArrayList<>();
        colors.add(Color.parseColor("#4572A7"));
        colors.add(Color.parseColor("#AA4643"));
        dataSet.setColors(colors);
        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(15f);
        data.setValueTextColor(Color.WHITE);
        mpieChart_1.setData(data);
        mpieChart_1.highlightValue(null);
        mpieChart_1.invalidate();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(viewList.get(position));
    }

    @Override
    public int getCount() {
        return viewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onValueSelected(Entry e, Highlight h) {

    }

    @Override
    public void onNothingSelected() {

    }
}
